﻿// Nail framework
//
// Copyright © Frank Nagl, 2008
// admin@franknagl.de
// www.franknagl.de
//
namespace Nail
{
    using System.Drawing.Imaging;
    using System;
    /// <summary>
    /// Provides static methods to extract the image format from images.
    /// </summary>
    public class ImageFormatDetector
    {
        /// <summary>
        /// Extracts the image format from a given raw image format.
        /// </summary>
        /// <param name="rawFormat">The given raw image format.</param>
        /// <returns>The extracted image format.</returns>
        public static ImageFormat GetImageFormatFromRaw(ImageFormat rawFormat)
        {
            if (rawFormat.Equals(ImageFormat.Bmp))
                return ImageFormat.Bmp;
            if (rawFormat.Equals(ImageFormat.Emf))
                return ImageFormat.Emf;
            if (rawFormat.Equals(ImageFormat.Exif))
                return ImageFormat.Exif;
            if (rawFormat.Equals(ImageFormat.Gif))
                return ImageFormat.Gif;
            if (rawFormat.Equals(ImageFormat.Icon))
                return ImageFormat.Icon;
            if (rawFormat.Equals(ImageFormat.Jpeg))
                return ImageFormat.Jpeg;
            if (rawFormat.Equals(ImageFormat.MemoryBmp))
                return ImageFormat.MemoryBmp;
            if (rawFormat.Equals(ImageFormat.Png))
                return ImageFormat.Png;
            if (rawFormat.Equals(ImageFormat.Tiff))
                return ImageFormat.Tiff;
            if (rawFormat.Equals(ImageFormat.Wmf))
                return ImageFormat.Wmf;

            throw new FormatException("No valid image format detected.");
            //return null;
        }
    }
}
